package io.tij;

import java.io.FileOutputStream;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;
import java.util.concurrent.TimeUnit;

public class FileLocking
{
  public static void main(String[] args) throws Exception{
    FileChannel fc = new FileOutputStream("file.txt").getChannel();
    FileLock fl = fc.tryLock();
    if(fl != null){
      System.out.println("File Locked");
      TimeUnit.MILLISECONDS.sleep(100);
      fl.release();
      System.out.println("Release Lock");
    }    
  }
}
